﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Core
{
    public static partial class user
    {
		public static dynamic recoveryUserPassword(string username, string sid, string remotePassword, string password)
        {
            var sql = new Sql.SqlDataContext();
            var u = sql.User.FirstOrDefault(row => row.username.ToLower() == username.ToLower());
            if (u == null) return new
                {
                    success = false,
                    msg = "用户不存在"
                };
			if (u.sid == null) return new {
				success = false,
				msg = "只有校内学生可自助恢复密码！"
			};
			if (u.sid != sid) return new {
				success = false,
				msg = "学号不匹配！"
			};

			var h = new EMIS.Helper();
			if (!h.Login(sid, remotePassword)) return new
                {
                    success = false,
                    msg = "本科教学平台密码验证失败！"
                };
            u.password = password;
            sql.SubmitChanges();
            return new
            {
                success = true
            };
        }
    }
}
